package cn.luncene;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.junit.Test;
import org.wltea.analyzer.lucene.IKAnalyzer;

import java.io.File;

/**
 * @author Administrator
 * @Title: 萧萧
 * @ProjectName lucene
 * @Description: 修改索引库
 * @date 2018/9/29 19:05
 */
public class updateIndex {
    @Test
    public void test() throws Exception{
        Directory directory = FSDirectory.open(new File("I:\\视频\\lucene学生\\02.参考资料\\index").toPath());
        IndexWriterConfig config = new IndexWriterConfig(new IKAnalyzer());
        //创建IndexWriter对象
        IndexWriter indexWriter = new IndexWriter(directory,config);

        //创建文档对象document
        Document document = new Document();
        document.add(new TextField("fileName","更新的文档", Field.Store.YES));
        document.add(new TextField("content","我是卖报的小行家", Field.Store.YES));

        indexWriter.updateDocument(new Term("name","web"),document);
        indexWriter.close();
    }
}
